package com.qf.service;

import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.qf.dao.UserAMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

/**
 * @version v1.0.0
 * @Description:
 * @author: 姜红凯
 * @date: 2022.03.23
 * @since 1.0
 */
@Service
public class UserAServiceImpl implements UserAService {
    @Autowired
    UserAMapper userAMapper;

    @Autowired
    RestTemplate restTemplate;

    @Override
    //本地事务
    @Transactional
    //分布式事务
    @LcnTransaction
    public String descA() {
        //1.账户A扣钱
        String str = String.valueOf(userAMapper.descUserA());
        //2.账户B加钱

        String tempStr = restTemplate.getForObject("http://localhost:8082/userB/addB", String.class);
        System.out.println("==========" + tempStr);
        return "A ok!";


    }
}
